package com.sunmi.usercenter.ui.activity.fragment;


import com.sunmi.usercenter.Constant;
import com.sunmi.usercenter.R;
import com.sunmi.usercenter.bean.FmInfo;

import android.graphics.Color;
import android.os.Bundle;
import android.text.Html;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class StartRegisterFragment extends SuperFragment implements View.OnClickListener{

	private View mView;
	private LinearLayout mLinRegisterNewAccount,mLinLogin,mLinNext;
	private ImageView mImgArrow1,mImgArrow2;
	private TextView mTxtSkip,mTxtRegister,mTxtLogin;
	private static final String SELECT_REGISTER_NEW_ACCOUNT = "0x01";
	private static final String SELECT_REGISTER_LOGIN = "0x00";
	private String select = SELECT_REGISTER_NEW_ACCOUNT;

	
	@Override
	public void onActivityCreated(Bundle savedInstanceState) {
		super.onActivityCreated(savedInstanceState);
		initView();
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		super.onCreateView(inflater, container, savedInstanceState);
		return mView = inflater.inflate(R.layout.fragment_register, container, false);
	}

	/**
	 * 初始化
	 */
	private void initView(){
		mActivity.SetStatusColorf5f5f5();
		Constant.CLASS_FRAGMENT = Constant.DoubleClickExit;
		mLinRegisterNewAccount = (LinearLayout)mView.findViewById(R.id.lin_register_new_account);
		mLinLogin = (LinearLayout)mView.findViewById(R.id.lin_login);
		
		TextView mTxtTitle = (TextView) mView.findViewById(R.id.title);
		layoutTitle(mTxtTitle);
		mLinNext = (LinearLayout)mView.findViewById(R.id.btn);
		mImgArrow1 = (ImageView)mView.findViewById(R.id.img_arrow_right1);
		mImgArrow2 = (ImageView)mView.findViewById(R.id.img_arrow_right2);
		mTxtSkip = (TextView)mView.findViewById(R.id.txt_skip);
		mTxtRegister = (TextView)mView.findViewById(R.id.txt_register_new_sunmi_account);
		mTxtLogin = (TextView)mView.findViewById(R.id.txt_use_account);
		mTxtSkip.setText(Html.fromHtml("<u>"+getResources().getString(R.string.skip)+"</u>"));
		mLinRegisterNewAccount.setOnClickListener(this);
		mLinLogin.setOnClickListener(this);
		mLinNext.setOnClickListener(this);
		mTxtSkip.setOnClickListener(this);
	}


	/**
	 * 点击注册新账号
	 */
	private void clickRegister(){
		select = SELECT_REGISTER_NEW_ACCOUNT;
		mImgArrow1.setVisibility(View.VISIBLE);
		mTxtRegister.setTextColor(Color.parseColor("#ff3c00"));
		mTxtLogin.setTextColor(Color.parseColor("#222222"));
		mImgArrow2.setVisibility(View.INVISIBLE);
	}

	/**
	 *点击用已有账号登录
	 */
	private void clickToLogin(){
		select = SELECT_REGISTER_LOGIN;
		mImgArrow2.setVisibility(View.VISIBLE);
		mTxtLogin.setTextColor(Color.parseColor("#ff3c00"));
		mTxtRegister.setTextColor(Color.parseColor("#222222"));
		mImgArrow1.setVisibility(View.INVISIBLE);
	}

	/**
	 * 点击下一步按钮
	 */
	private void clickNext(){
		switch (select){
			case SELECT_REGISTER_NEW_ACCOUNT:
				Constant.mInputToCode.setFramgmentCode(0);
				openFM(new FmInfo(RegisterFragment.class, 0));
				break;
			case SELECT_REGISTER_LOGIN:
				openFM(new FmInfo(LoginFragment.class,null));
				break;
		}
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()){
			case R.id.lin_register_new_account:
				clickRegister();
				break;
			case R.id.lin_login:
				clickToLogin();
				break;
			case R.id.btn:
				clickNext();
				break;
			case R.id.txt_skip:
				exitMe();
				getActivity().finish();
				break;
		}
	}
}
